<template>
  <el-dialog title="商品查询" :visible.sync="visible" append-to-body fullscreen center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <div class="avue-crud">
      <el-table :data="dataList" height="calc(100vh - 215px)" ref="goodsTable" border v-loading="dataListLoading"
        highlight-current-row @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column prop="goodsBarcode" label="商品代码"></el-table-column>
        <el-table-column prop="goodsName" label="商品名称"></el-table-column>
        <el-table-column prop="spec" label="型号" width="150"></el-table-column>
        <el-table-column prop="unitType" label="单位" width="150"></el-table-column>
        <el-table-column prop="ctgId" label="零售价格" width="150"></el-table-column>
        <el-table-column prop="stockName" label="仓位" width="150"></el-table-column>
        <el-table-column prop="goodsQuantity" label="库存数量" width="150"></el-table-column>
      </el-table>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="visible = false" v-prevent-re-click>确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { storageFetchList } from '@/api/eims/allocation'
  import { mapGetters } from 'vuex'
  export default {
    data() {
      return {
        visible: false,
        searchData: {},
        idList: [],
        dataList: [],
        dataListLoading: false
      }
    },
    methods: {
      init(data) {
        this.visible = true
        let list = data.data
        let stockId = data.params.stockId
        this.dataListLoading = true
        storageFetchList({ stockId: stockId }).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.dataListLoading = false
            this.$nextTick(() => {
              list.forEach(item => {
                for (let i = 0; i < this.dataList.length; i++) {
                  if (item.id == this.dataList[i].id) {
                    this.$refs.goodsTable.toggleRowSelection(this.dataList[i], true)
                  }
                }
              })
            })
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      // 选择添加商品
      handleSelectionChange(val) {
        let list = []
        val.forEach(item => {
          let listObj = {
            id: item.id,
            barcode: item.barcode,
            name: item.name,
            spec: item.spec
          }
          list.push(listObj)
        })
        this.$emit('showBrandList', val)
      }
    }
  }
</script>

<style>
</style>
